/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package east2west.action;

import east2west.dao.SaleCarDAO;
import east2west.dao.SeasonDAO;
import east2west.dto.CarModelDTO;
import east2west.dto.CarTypesDTO;
import east2west.dto.SaleCarDTO;
import east2west.dto.SeasonsDTO;
import east2west.service.CarModelService;
import east2west.service.CarTypeService;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author nguyendat
 */
public class SaleCarAction extends DispatchAction {

    SaleCarDAO saleCarSer = new SaleCarDAO();
    CarModelService carmodeser = new CarModelService();
    CarTypeService cartypeser = new CarTypeService();
    SeasonDAO seasonser = new SeasonDAO();
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";

    /**
     * This is the Struts action method called on
     * http://.../actionPath?method=myAction1,
     * where "method" is the value specified in <action> element : 
     * ( <action parameter="method" .../> )
     */
    public ActionForward listAll(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<SaleCarDTO> listSaleCar = saleCarSer.listAll();
        request.setAttribute("listsalecar", listSaleCar);
        request.setAttribute("page", "salecar.page");

        return mapping.findForward(SUCCESS);
    }

    /**
     * This is the Struts action method called on
     * http://.../actionPath?method=myAction2,
     * where "method" is the value specified in <action> element : 
     * ( <action parameter="method" .../> )
     */
    public ActionForward listFillterM(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);
        ArrayList<CarModelDTO> listMode = carmodeser.readByAll();
        request.setAttribute("listMode", listMode);
        request.setAttribute("page", "salecarmode.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward listFillterT(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);
        ArrayList<CarTypesDTO> listType = cartypeser.readByAll();
        request.setAttribute("listType", listType);
        request.setAttribute("page", "salecartype.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward listFillterP(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);

        request.setAttribute("page", "salecarcost.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward listFillterA(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);
           ArrayList<SaleCarDTO> listFilll = saleCarSer.listFillterAir();
        request.setAttribute("listFilll", listFilll);

        request.setAttribute("page", "salecarair.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward listFillterS(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);
        ArrayList<SeasonsDTO> listSeason = seasonser.findBySeasonName();
        request.setAttribute("listSeason", listSeason);
        request.setAttribute("page", "salecarseason.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward TotalM(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);
        ArrayList<CarModelDTO> listMode = carmodeser.readByAll();
        request.setAttribute("listMode", listMode);

        int id = Integer.parseInt(request.getParameter("mode"));
        float sum = saleCarSer.TotalMode(id);
        request.setAttribute("sum", sum);
        request.setAttribute("page", "salecarmode.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward TotalT(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int id = Integer.parseInt(request.getParameter("type"));
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);
        ArrayList<CarTypesDTO> listType = cartypeser.readByAll();
        request.setAttribute("listType", listType);


        float sum = saleCarSer.TotalType(id);
        request.setAttribute("sum", sum);
        request.setAttribute("page", "salecartype.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward TotalP(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        float price1 = Float.parseFloat(request.getParameter("price1"));
        float price2 = Float.parseFloat(request.getParameter("price2"));

        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);



        float sum = saleCarSer.TotalCost(price1, price2);
        request.setAttribute("price1", price1);
        request.setAttribute("price2", price2);
        request.setAttribute("sum", sum);
        request.setAttribute("page", "salecarcost.page");


        return mapping.findForward(SUCCESS);
    }

    public ActionForward TotalA(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String air = request.getParameter("air");
        boolean airb = false;
        if (air.equals("Yes")) {
            airb = true;

        }
        ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);

 ArrayList<SaleCarDTO> listFilll = saleCarSer.listFillterAir();
        request.setAttribute("listFilll", listFilll);

        float sum = saleCarSer.TotalAir(airb);
        request.setAttribute("sum", sum);
        request.setAttribute("page", "salecarair.page");


        return mapping.findForward(SUCCESS);
    }
     public ActionForward TotalS(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {

         int season = Integer.parseInt(request.getParameter("season"));
         SeasonsDTO seasonDTO = seasonser.readByIdMonth(season);
        float sum = saleCarSer.totalSeason(seasonDTO.getStart(), seasonDTO.getEnd());

 ArrayList<SaleCarDTO> listFill = saleCarSer.listFillter();
        request.setAttribute("listFill", listFill);

          ArrayList<SeasonsDTO> listSeasonName = seasonser.findBySeasonName();
        request.setAttribute("listSeason", listSeasonName);
        request.setAttribute("sum", sum);
        request.setAttribute("month1", seasonDTO.getStart());
        request.setAttribute("month2",  seasonDTO.getEnd());
        request.setAttribute("page","salecarseason.page");

        return mapping.findForward(SUCCESS);

    }
}
